package com.openatc.agent.service;

import com.openatc.agent.utils.ApplicationContextProvider;
import com.openatc.agent.utils.RedisTemplateUtil;
import com.openatc.comm.data.MessageData;
import com.openatc.core.common.Constants;
import com.openatc.core.model.RESTRet;

/**
 * @author ：panleilei
 * @description 操作信号机特征参数
 * @modified By：
 * @version:
 * @date ：Created in 2023/4/14 13:41
 */
public abstract class FeatureRequest extends GenericMsgStrategy {
    @Override
    public RESTRet successSetProcess(MessageData requestData, RESTRet responseData) {
        String infotype = requestData.getInfotype();
        // 如果是特征参数的下载，向redis发布成功下载参数的消息
        if (infotype.contains("feature/")) {
            publishFeatureSetSuccessMsg(requestData);
        }
        return super.successSetProcess(requestData, responseData);
    }

    /**
     * 发布参数下载成功的消息
     * @param requestData
     */
    protected void publishFeatureSetSuccessMsg(MessageData requestData) {
        RedisTemplateUtil redisTemplateUtil = ApplicationContextProvider.getBean(RedisTemplateUtil.class);
        String channel = Constants.FEATURE_SET_CHANNEL + requestData.getInfotype() + ":" + requestData.getAgentid();
        String message = gson.toJson(requestData);
        redisTemplateUtil.publish(channel,message);
        redisTemplateUtil.setValue(channel,message);
        System.out.println("=========" + channel);
    }

}
